package com.cx.service.yitu;

import com.cx.service.yitu.config.RetrofitInterceptor;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient;
import org.springframework.stereotype.Service;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @ClassName: RetrofitService
 * @Description: 初始化
 * @Author: cx
 * @Date: 2023/10/17 15:44
 **/
@Slf4j
@Service
public class RetrofitService {
    private Map<String, Retrofit> retrofitMap = new HashMap<>();


    public <T> T getApiByIPService(Class<T> serviceClass) {
        Retrofit retrofit = init();

        return retrofit.create(serviceClass);
    }

//    private void getToken(String str1, String str2, String str3) {
//        System.out.println(str1);
//        System.out.println(str2);
//        System.out.println(str3);
//
//
//    }


    //  @SneakyThrows
    private Retrofit init() {
        OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(5L, TimeUnit.SECONDS)
                .addInterceptor(new RetrofitInterceptor())
                .build();


        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://172.16.10.166/")
                .addConverterFactory(GsonConverterFactory.create())
                .client(client)
                .build();
        return retrofit;
    }
}